define(["jquery","qrcode","bbcare","echarts",
    "scprit/followup/app/motionAndBG/motionAndBG.ui.js",
    "scprit/followup/app/motionAndBG/motionAndBG.servers.js","scprit/followup/app/datatable/datatable.ui.js","oms_config/root"],function ($,qrcode,$bb,echarts,$ui,$servers,$datatableUi,$root) {
    var event = {},authNo = '';
    event.init = function(params){
        /*
         * 血糖和运动选项卡；
         * */
        $('.tab-check>div.tabs').click(function(){
            $(this).addClass('active').siblings('.tabs').removeClass('active');
            $ui.searchConInit({"id":"#heading-con"});
            if($(this).index() == 1){
            	$("#bloodsugar").next("div.row").removeClass("hidden");
            	$("#bloodsugar").removeClass("hidden");
            	$("#motionCur,#sport").addClass("hidden");
            }else if($(this).index() == 0){
            	$("#motionCur").html("");
            	$("#motionCur,#sport").removeClass("hidden");
            	$("#bloodsugar").prev("div.row").remove();
            	$("#bloodsugar").next("div.row").addClass("hidden");
            	$("#bloodsugar").addClass("hidden");
            }else{
            	$("#motionCur").html("");
            	$("#motionCur").removeClass("hidden");
            	$("#bloodsugar").prev("div.row").remove();
            	$("#bloodsugar").next("div.row").addClass("hidden");
                $("#bloodsugar,#sport").addClass("hidden");
            }
            //自定义：
            $("#heading-con").off('click','#self_defined');
            $("#heading-con").on('click','#self_defined',function(){
                $(this).attr("class","btn btn-info");
                $("#lastMonth").attr("class","btn btn-default");
                var fromTime = $("#fromTime").val();
                var endTime = $("#endTime").val() ;
                var index = $(".tab-check>div.active").index();
                if(index == 1){
                	getMotionCurData(params,fromTime,endTime,'10');
                }else if(index == 0){
                	switch($(".sport-tabs>div.active").index()){
                		case 0:getMotionCurData(params,fromTime,endTime,'20');break; 
                		case 1:getMotionCurData(params,fromTime,endTime,'21');break; 
                	}
                }else if(index == 2){
                	 getMotionCurData(params,fromTime,endTime,'30');
                }else if(index == 3){
                	 getMotionCurData(params,fromTime,endTime,'40');
                }
            });

            $("#heading-con").off('change','#fromTime,#endTime');
            $("#heading-con").on('change','#fromTime,#endTime',function(){
                var fromTime = $("#fromTime").val();
                var endTime = $("#endTime").val() ;
                var index = $(".tab-check>div.active").index();
                if(index == 1){
                    getMotionCurData(params,fromTime,endTime,'10');
                }else if(index == 0){
                	switch($(".sport-tabs>div.active").index()){
	            		case 0:getMotionCurData(params,fromTime,endTime,'20');break; 
	            		case 1:getMotionCurData(params,fromTime,endTime,'21');break; 
	            	}
                }else if(index == 2){
                	 getMotionCurData(params,fromTime,endTime,'30');
                }else if(index == 3){
                	 getMotionCurData(params,fromTime,endTime,'40');
                }
            });
            //运动TAB切换；
            $("#sport").off('click','.sport-tab');
            $("#sport").on('click','.sport-tab',function(){
            	$(this).addClass('active').siblings('.sport-tab').removeClass('active');
                var fromTime = $("#fromTime").val();
                var endTime = $("#endTime").val() ;
                var index = $(".tab-check>div.active").index();
                if(index == 1){
                    getMotionCurData(params,fromTime,endTime,'10');
                }else if(index == 0){
                	switch($(".sport-tabs>div.active").index()){
	            		case 0:getMotionCurData(params,fromTime,endTime,'20');break; 
	            		case 1:getMotionCurData(params,fromTime,endTime,'21');break; 
	            	}
                }else if(index == 2){
                	 getMotionCurData(params,fromTime,endTime,'30');
                }else if(index == 3){
                	 getMotionCurData(params,fromTime,endTime,'40');
                }
            });
            //最后一个月；
            $("#heading-con").off('click','#lastMonth');
            $("#heading-con").on('click','#lastMonth',function(){
                $(this).attr("class","btn btn-info");
                $("#self_defined").attr("class","btn btn-default");
                var fromTime,endTime ;
                fromTime = getBeforeDate(30);
                endTime = time(new Date());
                var index = $(".tab-check>div.active").index();
                if(index == 1){
                    getMotionCurData(params,fromTime,endTime,'10');
                }else if(index == 0){
                	switch($(".sport-tabs>div.active").index()){
	            		case 0:getMotionCurData(params,fromTime,endTime,'20');break; 
	            		case 1:getMotionCurData(params,fromTime,endTime,'21');break; 
	            	}
                }else if(index == 2){
                	 getMotionCurData(params,fromTime,endTime,'30');
                }else if(index == 3){
                	 getMotionCurData(params,fromTime,endTime,'40');
                }
            });
            $("#lastMonth").click();
        });
        $('.tab-check>div.tabs').eq(0).click();

        /* 华米授权  */
        $('.tab-check>div>div.huaMi-authority').click(function(){
            var conAuth = $.trim($("#authority_status").html());
            if(conAuth == "已授权"){
                var  conTips = {
                    "title":"提示信息",
                    "tips":'您已授权，再次授权请使用本次授权账号登录小米运动',
                    "btn1":"再次授权",
                    "btn0":"取消"
                };
                $ui.dialogInit({"id":"#modalBox","data":conTips});
                $('#myModal').modal('show');
                $("#myModal").off("click","button");
                $("#myModal").on("click","button",function(){
                    var flag = $(this).attr('flag');
                    if(flag == "10") {
                        $('#myModal').modal('hide');
                        authority(params);
                    }
                });
            }else if(conAuth == "未授权"){
                authority(params);
            }
        });
    };
    /*
     * 删除患者
     * */
    var deletePatientFn = function(){
        var params = $(this).data('params');
        var sessinonName = JSON.parse($bb.getSessionStorage("account")).alias;
        var inParams = {
            "oprInfo":{
                "opCode":"1017",
                "opNote":"【"+ sessinonName +"】医生将【"+ params.patientName +"】患者从"+ params.queuename +"删除",
                "opType":"2"
            },
            "patientInfo":{
                "followQueueId":params.followQueueId,
                "patientId":params.patientId,
                "ptSchemeId":params.patientSchemeId
            }
        };
        inParams.callback = function(data){
            if(data.success){
                $bb.selectNavbar('workBenchDiabetes');
                $bb.toastShow("删除成功",1500);
            }else{
                $bb.toastShow("删除失败",1500);
            }
        };
        $bb.toastConfirmShow($servers.deletePatient,inParams,'确定删除该队列下的患者么？');
    };

    /*
     * 授权回调函数：
     * */
    //中文转码：
    function toUtf8(str) {
        var out, i, len, c;
        out = "";
        len = str.length;
        for(i = 0; i < len; i++) {
            c = str.charCodeAt(i);
            if ((c >= 0x0001) && (c <= 0x007F)) {
                out += str.charAt(i);
            } else if (c > 0x07FF) {
                out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
                out += String.fromCharCode(0x80 | ((c >>  6) & 0x3F));
                out += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));
            } else {
                out += String.fromCharCode(0xC0 | ((c >>  6) & 0x1F));
                out += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));
            }
        }
        return out;
    }
    var authorityCallback = function(data){
        var url = data.data.redirectUrl;
        $("#erweima_authority").qrcode({
            render: "canvas",
            width: 256,
            height:256,
            text: toUtf8(url)
        });
    };
    /*
    * 授权
    * */
    var authority = function(params){
        $ui.authorityInit({"id":"#modalBox"});
        $('#myAuthority').modal('show');
        var inParams = {"userId":params.patientId};
        $servers.authority(inParams,authorityCallback);
    };
    /*
     * 获取运动曲线数据：
     * */
    var getMotionCurData = function(params,fromTime,endTime,flag){
        var inParams = {
            "userId":params.patientId,
            "startTime":fromTime,
            "endTime":endTime
        };
        var params1 = $.extend({},params,{"flag":flag});
        if(flag == "20"){//flag：20 运动-步数和距离
        	$servers.getMotionCurData(inParams,getMotionCurDataCallback,params1);
        }else if(flag == "21"){//flag：21 运动-体操和哑铃
        	$servers.getGymnasticBarbellData(inParams,getMotionCurDataCallback,params1);
        }else if(flag == "10"){ // flag : 10 血糖
        	$bb.setIocalStorage("patientId",params.patientId);
        	$("#motionCur").html("");
        	$datatableUi.init({
                "id": "bloodsugar",
                "options": $servers.getOptions()
            });
        }else if(flag == "30"){ // flag : 30 睡眠
        	var inParams = {
    			"userId":params.patientId,
    			"startDate":fromTime,
    			"endDate":endTime
        	};
            $servers.getSleepData(inParams,getMotionCurDataCallback,params1);
        }else if(flag == "40"){ // flag : 40 体重
            $servers.getWeightData(inParams,getMotionCurDataCallback,params1);
        }
    };
    var getMotionCurDataCallback = function(data,params){
        if(data.data.hasOwnProperty("status")){
            var authorityStatus = data.data.status == "1" ? "已授权":"未授权";
            $("#authority_status").html(authorityStatus);
        }
        var status = data.data.bindStatus == '1' ? '已发放': "未发放";
        var operate = data.data.bindStatus == '1' ? '回收': "发放";
        $("#equipStatus").html('设备状态：<span class="status">'+ status +'</span> <span class="status-operate" status = "'+ data.data.bindStatus +'" id = "'+ data.data.id +'">'+ operate +'</span>');
        var recordList = data.data.recordList?data.data.recordList:data.data.list;
        if(recordList.length > 0){
            var series = dataDeal(recordList,params.flag);
            if(params.flag == "20"){
            	getMotionOptions(series);
            }else if(params.flag == "21"){
        		getSportOptions(series);
            }else if(params.flag == "10"){
	        	  
            }else if(params.flag == "30"){
            	getSleepOptions(series);
            }else if(params.flag == "40"){
            	getWeightOptions(series);
            }
        }else{
            $("#motionCur").html("<p>当前时间段无监测数据……</p>");
        }
        $('.panel-body').off('click','.status-operate');
        $('.panel-body').on('click','.status-operate',function(){
            var status = $(this).attr('status');
            var con = {};
            if(status ==  1){
                var unbindId = $(this).attr('id');//解绑id
                con = {
                    "title":"回收",
                    "tip":'此操作将回收设备<span class="status" >'+ data.data.deviceId +'</span>',
                    "btn1":"确认回收",
                    "btn0":"取消"
                };
            }else if(status == 0){
                var tabIndex = $('.tab-check>div.tabs.active').index(),tips;
                if(tabIndex == 0){//运动管理
                    authNo = Math.ceil(Math.random()*100000000000);//手环序号随机数
                    tips = '您正在为 <span class="status" >'+ data.data.userName +'</span> 发放设备<span class="status" id="xiaoMi">手环XMSH04HM_'+ authNo +'</span></div>'
                }else if(tabIndex == 1){//血糖管理
                    tips = '您正在为 <span class="status" >'+ data.data.userName +'</span> 发放设备，请输入你要发放的设备：<div class="col-md-8 col-md-push-2"><input type = "text" id="equipId" class="form-control" placeholder="请输入设备id"></div>';
                }
                con = {
                    "title":"发放",
                    "tip":tips,
                    "btn1":"确认发放",
                    "btn0":"取消"
                };
            }
            $ui.dialogInit({"id":"#modalBox","data":con});
            $(".modal-body").html(con.tip);
            $('#myModal').modal({backdrop: "static",keyboard:false,show:true});//点击背景空白处不会关闭；按下键盘esc不会被关闭
            $("#myModal").on("click","button",function(){
                var flag = $(this).attr('flag');
                if(flag == 1){
                    var inParams = {
                        "userId":params.patientId,
                        "type":params.flag
                    };
                    if(status == 1){//解绑
                        inParams.id = unbindId;
                        $servers.equipUnbind(inParams,function(data){
                            $bb.toastShow("回收成功",1500);
                            $('#myModal').modal('hide');
                            $('.tab-check>div.tabs.active').click();
                        });
                    }
                    if(status == 0){//绑定
                        var tabIndex = $('.tab-check>div.tabs.active').index(),equipId;
                        if(tabIndex == 0){//运动管理

                            equipId = $.trim($("#xiaoMi").html());
                        }else if(tabIndex == 1){//血糖管理
                            equipId = $.trim($("#equipId").val())
                        }
                        inParams.deviceId = equipId;
                        $servers.equipBind(inParams,function(data){
                            $bb.toastShow("发放成功",1500);
                            $('#myModal').modal('hide');
                            $('.tab-check>div.tabs.active').click();
                        });
                    }
                }
            });
        });
        /*
        * 修改患者信息；
        * */
        $(".box").on("click","#modify",function(){
            $(this).data('modify',params);
            modifyUserInfo(this);
        });

        /*
        * 删除患者
        * */
        var params2 = $.extend({},params,{"patientName":data.data.userName});
        var topbars = [
            {
                "icon":"fa fa-trash",
                "name":"删除患者",
                "callback":deletePatientFn,
                "params":params2
            }
        ];
        $bb.toolbar(topbars);
    };
    //修改患者信息
    var modifyUserInfo = function(obj){
        var params = $(obj).data('modify');
        $bb.openPage('modifyPatientDiabetes',params);
    };
    /*
    * 数据处理：
    * */
    function getBeforeDate(n){
        var n = n;
        var d = new Date();
        var year = d.getFullYear();
        var mon=d.getMonth()+1;
        var day=d.getDate();
        if(day <= n){
            if(mon>1) {
                mon=mon-1;
            }
            else {
                year = year-1;
                mon = 12;
            }
        }
        d.setDate(d.getDate()-n);
        year = d.getFullYear();
        mon=d.getMonth()+1;
        day=d.getDate();
        s = year+"-"+(mon<10?('0'+mon):mon)+"-"+(day<10?('0'+day):day);
        return s;
    }
    var formate = function(d){
        return d>9?d:'0'+d;
    };
    var time = function(d){
        var year=d.getFullYear();
        var day=d.getDate();
        var month=+d.getMonth()+1;
        var f=year+"-"+formate(month)+"-"+formate(day);
        return f;
    };
    var dataDeal = function(data,flag){
        var km = [],wb = [],kcal = [],time = [],bg = [],testDate,gymnasticTimes = [],barbellTimes = [],deepSleepTime=[],shallowSleepTime=[],wakeTime=[],weightNumber=[];
        for(var i = 0 ;i < data.length ; i++){
            if(flag == "20"){
                km.unshift(data[i].distance/1000); // 千米
                wb.unshift(data[i].steps/10000);//万步
                kcal.unshift(data[i].calories/1000);//千卡
                testDate = data[i].testDate;
            }else if(flag == "21"){
            	gymnasticTimes.unshift(data[i].gymnasticTimes); // 体操运动分钟数
            	barbellTimes.unshift(data[i].barbellTimes);//杠铃运动分钟数
                testDate = data[i].testDate;
            }else if(flag == "30"){
            	deepSleepTime.unshift(data[i].deepSleepTime); //深度睡眠时间
            	shallowSleepTime.unshift(data[i].shallowSleepTime);//浅度睡眠时间
            	wakeTime.unshift(data[i].wakeTime);//醒的时间
                testDate = $bb.simple.getDateFormat(new Date(data[i].start*1000)).date;
            }else if(flag == "40"){
            	weightNumber.unshift(data[i].weightNumber); //体重
                testDate = data[i].testDate;
            }else if(flag == "10"){
                testDate = data[i].testTime;
                bg.unshift(data[i].sugarValue);//血糖
            }
            time.unshift(testDate);
        }
        var params = {};
        if(flag == "20"){
            params = {"km":km, "wb":wb, "kcal":kcal, "time":time}
        }else if(flag == "21"){
            params = {"gt":gymnasticTimes, "bb":barbellTimes,"time":time}
        }else if(flag == "30"){
            params = {"deepSleepTime":deepSleepTime,"shallowSleepTime":shallowSleepTime,"wakeTime":wakeTime,"time":time}
        }else if(flag == "40"){
            params = {"wt":weightNumber, "time":time}
        }else if(flag == "10"){
            params = {"bg":bg, "time":time}
        }
        return params;
    };
    /*
    * 配置参数：
    * */
    var getMotionOptions = function(obj){
        var myChart = echarts.init(document.getElementById('motionCur'));
        var option = {
            title : {},
            grid: {
                bottom: "20%",
                left:"5%",
                right:"5%"
            },
            tooltip : {
                show:"true",
                trigger: 'axis',
                textStyle:{
                    align:'left'
                },
                formatter: function (params,ticket,callback) {
                    var val = params[0].name + "<br />";
                    for(var i = 0 ;i < params.length;i++){
                        var unit = params[i].seriesName == "步数（万步）" ? "万步" : params[i].seriesName == "距离（千米）" ? "千米": "千卡";
                        var color = params[i].color == "transparent" ? "#FFDB96" : params[i].color;
                        val +=  '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background-color:' + color + '"></span>'+params[i].value + unit + '<br />' ;
                    }
                    return val;
                }
            },
            legend: {
                data:["步数（万步）","距离（千米）","-"]//消耗能量（千卡）
            },
            dataZoom: [
                {
                    type:"slider",
                    show: true,
                    realtime: true,
                    start:10,
                    end: 90
                },
                {
                    type: 'inside',
                    realtime: true,
                    start: 10,
                    end: 90
                }
            ],
            xAxis : [
                {
                    type : 'category',
                    boundaryGap : false,
                    axisLine: {onZero: false},
                    splitLine:{
                        show: false//保留网格线
                    },
                    axisLabel:{
                        rotate:"45"
                    },
                    data:obj.time
                }
            ],
            yAxis:[
                {
                    name:"万步",
                    position:"left",
                    splitLine:{
                        show: false//保留网格线
                    },
                    type: 'value'
                },
                {
                    name:"千米",
                    position:"right",
                    splitLine:{
                        show: false//保留网格线
                    },
                    type: 'value'
                },
                {
                    show:"false",
                    name:"千卡",
                    position:"right",
                    axisLabel:{
                        show:false
                    },
                    axisTick:{
                        show: false
                    },
                    splitLine:{
                        show: false//保留网格线
                    },
                    type: 'value'
                }
            ],
            series: [
                {
                    name:'步数（万步）',
                    type:'line',
                    symbol:"circle",
                    animation: false,
                    areaStyle: {
                        normal: {
                            color:"transparent"
                        }
                    },
                    itemStyle : {
                        normal : {
                            color:'#3E85F0'
                        }
                    },
                    lineStyle:{
                        normal : {
                            width:1,
                            color:'#3E85F0'
                        }
                    },
                    yAxisIndex:0,
                    data:obj.wb
                },
                {
                    name:'距离（千米）',
                    type:'line',
                    symbol:"circle",
                    animation: false,
                    areaStyle: {
                        normal: {
                            color:"transparent"
                        }
                    },
                    itemStyle : {
                        normal : {
                            color:'#993FF2'
                        }
                    },
                    lineStyle:{
                        normal : {
                            width:1,
                            color:'#993FF2'
                        }
                    },
                    yAxisIndex:1,
                    data:obj.km
                },
                {
                    name:'消耗能量（千卡）',
                    type:'line',
                    symbol:"circle",
                    animation: false,
                    areaStyle: {
                        normal: {
                            color:"transparent"
                        }
                    },
                    itemStyle : {
                        normal : {
                            color:"transparent"
                        }
                    },
                    lineStyle:{
                        normal : {
                            width:1,
                            color:"transparent"
                        }
                    },
                    yAxisIndex:2,
                    data:obj.kcal
                }
            ]
        };
        myChart.setOption(option);
    };
    
    var getSportOptions = function(obj){
    	var myChart = echarts.init(document.getElementById('motionCur'));
        var option = {
            title : {},
            grid: {
                bottom: "20%",
                left:"5%",
                right:"5%"
            },
            tooltip : {
                show:"true",
                trigger: 'axis',
                textStyle:{
                    align:'left'
                },
                formatter: function (params,ticket,callback) {
                    var val = params[0].name + "<br />";
                    for(var i = 0 ;i < params.length;i++){
                        var unit =  "分钟" ;
                        var color = params[i].color == "transparent" ? "#FFDB96" : params[i].color;
                        val +=  '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background-color:' + color + '"></span>'+params[i].value + unit + '<br />' ;
                    }
                    return val;
                }
            },
            legend: {
                data:["体操时长（min）","哑铃时长（min）","-"]//消耗能量（千卡）
            },
            dataZoom: [
                {
                    type:"slider",
                    show: true,
                    realtime: true,
                    start:10,
                    end: 90
                },
                {
                    type: 'inside',
                    realtime: true,
                    start: 10,
                    end: 90
                }
            ],
            xAxis : [
                {
                    type : 'category',
                    boundaryGap : false,
                    axisLine: {onZero: false},
                    splitLine:{
                        show: false//保留网格线
                    },
                    axisLabel:{
                        rotate:"45"
                    },
                    data:obj.time
                }
            ],
            yAxis:[
                {
                    name:"分钟",
                    position:"left",
                    splitLine:{
                        show: false//保留网格线
                    },
                    type: 'value'
                },
                {
                    name:"分钟",
                    position:"right",
                    splitLine:{
                        show: false//保留网格线
                    },
                    type: 'value'
                }
            ],
            series: [
                {
                    name:'体操时长（min）',
                    type:'line',
                    symbol:"circle",
                    animation: false,
                    areaStyle: {
                        normal: {
                            color:"transparent"
                        }
                    },
                    itemStyle : {
                        normal : {
                            color:'#3E85F0'
                        }
                    },
                    lineStyle:{
                        normal : {
                            width:1,
                            color:'#3E85F0'
                        }
                    },
                    yAxisIndex:0,
                    data:obj.gt
                },
                {
                    name:'哑铃时长（min）',
                    type:'line',
                    symbol:"circle",
                    animation: false,
                    areaStyle: {
                        normal: {
                            color:"transparent"
                        }
                    },
                    itemStyle : {
                        normal : {
                            color:'#993FF2'
                        }
                    },
                    lineStyle:{
                        normal : {
                            width:1,
                            color:'#993FF2'
                        }
                    },
                    yAxisIndex:1,
                    data:obj.bb
                }
            ]
        };
        myChart.setOption(option);
    }
    var getBGOptions = function(obj){
        var length = obj.time.length;
        var myChart = echarts.init(document.getElementById('motionCur'));
        var option = {
            title : {},
            grid: {
                bottom: "30%",
                left:"8%",
                right:"5%"
            },
            tooltip : {
                show:"true",
                trigger: 'axis',
                textStyle:{
                    align:'left'
                },
                formatter: function (params,ticket,callback) {
                    var val = params[0].name + "<br />";
                    for(var i = 0 ;i < params.length;i++) {
                        var color = params[i].color;
                        val += '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background-color:' + color + '"></span>' + params[i].seriesName +"&nbsp;"+ params[i].value +"</br>";
                    }
                        return val;
                }
            },
            legend: {
                data:["血糖"]
            },
            dataZoom: [
                {
                    type:"slider",
                    show: true,
                    realtime: true,
                    start:10,
                    end: 90
                },
                {
                    type: 'inside',
                    realtime: true,
                    start: 10,
                    end: 90
                }
            ],
            xAxis : [
                {
                    type : 'category',
                    boundaryGap : false,
                    axisLine: {onZero: false},
                    splitLine:{
                        show: false//保留网格线
                    },
                    axisLabel:{
                        rotate:"45"
                    },
                    data:obj.time
                }
            ],
            yAxis:[
                {
                    name:"mmol/l",
                    position:"left",
                    splitLine:{
                        show: false//保留网格线
                    },
                    type: 'value'
                }
            ],
            series: [
                {
                    name:'血糖',
                    type:'line',
                    symbol:"circle",
                    animation: false,
                    areaStyle: {
                        normal: {
                            color:"transparent"
                        }
                    },
                    itemStyle : {
                        normal : {
                            color:'#B8BDD9'
                        }
                    },
                    lineStyle:{
                        normal : {
                            width:1,
                            color:'#B8BDD9'
                        }
                    },
                    yAxisIndex:0,
                    data:obj.bg
                }
            ]
        };
        var empty = [],full = [];
        for(var i = 0;i<length;i++){
            empty.push(5.1);
            full.push(8.5);
        }
        option.series.push({
            name:'餐后一小时',
            type: 'line',
            symbol:'none',
            hoverAnimation:false,
            itemStyle: {
                normal: {
                    color:"#FBCCCC",
                }
            },
            lineStyle:{
                normal : {
                    color:"#FBCCCC",
                    width:2,
                    type:"dashed"
                }
            },
            data: full
        });
        option.series.push({
            name:'空腹',
            type: 'line',
            symbol:'none',
            hoverAnimation:false,
            itemStyle: {
                normal: {
                    color:"#FBCCCC",
                }
            },
            lineStyle:{
                normal : {
                    color:"#FBCCCC",
                    width:2,
                    type:"dashed"
                }
            },
            data: empty
        });
        myChart.setOption(option);
    };
    /*============睡眠曲线图例=====================*/
    var getSleepOptions = function(obj){
        var length = obj.time.length;
        console.info(obj.bg)
        var myChart = echarts.init(document.getElementById('motionCur'));
        var option = {
            title : {},
            grid: {
                bottom: "30%",
                left:"8%",
                right:"5%"
            },
            tooltip : {
                show:"true",
                trigger: 'axis',
                textStyle:{
                    align:'left'
                },
                formatter: function (params,ticket,callback) {
                    var val = params[0].name + "<br />";
                    for(var i = 0 ;i < params.length;i++) {
                        var color = params[i].color;
                        val += '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background-color:' + color + '"></span>' + params[i].seriesName +"&nbsp;"+ params[i].value +"分钟</br>";
                    }
                        return val;
                }
            },
            legend: {
                data:["深睡","浅睡","梦醒"]
            },
            dataZoom: [
                {
                    type:"slider",
                    show: true,
                    realtime: true,
                    start:10,
                    end: 90
                },
                {
                    type: 'inside',
                    realtime: true,
                    start: 10,
                    end: 90
                }
            ],
            xAxis : [
                {
                    type : 'category',
                    boundaryGap : false,
                    axisLine: {onZero: false},
                    splitLine:{
                        show: false//保留网格线
                    },
                    axisLabel:{
                        rotate:"45"
                    },
                    data:obj.time
                }
            ],
            yAxis:[
                {
                    name:"分钟",
                    splitLine:{
                        show: false//保留网格线
                    },
                    type: 'value'
                }
            ],
            series: [
                {
                    name:'深睡',
                    type:'bar',
                    stack: 'one',
                    barWidth:"20",
                    animation: false,
                    itemStyle : {
                        normal : {
                            color:'#6ecc99'
                        }
                    },
                    yAxisIndex:0,
                    data:obj.deepSleepTime
                },
                {
                    name:'浅睡',
                    type:'bar',
                    barWidth:"20",
                    stack: 'one',
                    animation: false,
                    itemStyle : {
                        normal : {
                            color:'#23a9e9'
                        }
                    },
                    yAxisIndex:0,
                    data:obj.shallowSleepTime
                },
                {
                    name:'梦醒',
                    type:'bar',
                    stack: 'one',
                    barGap:"130%",
                    animation: false,
                    barWidth:"20",
                    areaStyle: {
                        normal: {
                            color:"red"
                        }
                    },
                    itemStyle : {
                        normal : {
                            color:'yellow'
                        }
                    },
                    yAxisIndex:0,
                    data:obj.wakeTime
                }
                
            ]
        };
        myChart.setOption(option);
    };
    /*============体重曲线图例=====================*/
    var getWeightOptions = function(obj){
        var length = obj.time.length;
        var myChart = echarts.init(document.getElementById('motionCur'));
        var option = {
            title : {},
            grid: {
                bottom: "30%",
                left:"8%",
                right:"5%"
            },
            tooltip : {
                show:"true",
                trigger: 'axis',
                textStyle:{
                    align:'left'
                },
                formatter: function (params,ticket,callback) {
                    var val = params[0].name + "<br />";
                    for(var i = 0 ;i < params.length;i++) {
                        var color = params[i].color;
                        val += '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background-color:' + color + '"></span>' + params[i].seriesName +"&nbsp;"+ params[i].value +"kg</br>";
                    }
                        return val;
                }
            },
            legend: {
                data:["体重"]
            },
            dataZoom: [
                {
                    type:"slider",
                    show: true,
                    realtime: true,
                    start:10,
                    end: 90
                },
                {
                    type: 'inside',
                    realtime: true,
                    start: 10,
                    end: 90
                }
            ],
            xAxis : [
                {
                    type : 'category',
                    boundaryGap : false,
                    axisLine: {onZero: false},
                    splitLine:{
                        show: false//保留网格线
                    },
                    axisLabel:{
                        rotate:"45"
                    },
                    data:obj.time
                }
            ],
            yAxis:[
                {
                    name:"kg",
                    position:"left",
                    splitLine:{
                        show: false//保留网格线
                    },
                    type: 'value'
                }
            ],
            series: [
                {
                    name:'体重',
                    type:'line',
                    smooth:true,
                    symbol: 'none',
                    sampling: 'average',
                    itemStyle: {
                        normal: {
                            color: '#119BA9'
                        }
                    },
                    areaStyle: {
                        normal: {
                            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                offset: 0,
                                color: '#0a9fa6'
                            }, {
                                offset: 1,
                                color: 'rgb(255, 255, 255)'
                            }])
                        }
                    },
                    yAxisIndex:0,
                    data:obj.wt
                }
            ]
        };
        myChart.setOption(option);
    };
    return event;
});